package com.seednia.foundation.framework.util;

import java.util.Date;

public class DateUtils {
	
	public static final String FORMAT_ISO8601 = "yyyy-MM-dd'T'HH:mm:ss";
	
	public static final long diffMsecs(Date startDt, Date endDt)
	{
		return (endDt.getTime() - startDt.getTime())  ;
	}

	public static String deltaText(Date start, Date end)
	{
		StringBuffer retval = new StringBuffer();
		
		long delta = DateUtils.diffMsecs(start, end);
		
		int seconds = (int) ((delta / 1000) % 60);
		int minutes = (int) ((delta / 1000) / 60);
		int hours   = (int) ((delta / 1000) / 3600);
		int days    = (int) ((delta / 1000) / 86400);
		
		if (days > 0)
			retval.append(days).append("d ");
		if (hours > 0)
			retval.append(hours).append("h ");
		if (minutes > 0)
			retval.append(minutes).append("m ");
		if (seconds > 0)
			retval.append(seconds).append("s");
		
				
		return retval.toString();
	}
}
